home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / host contacted / jikes.lha / jikes-1.11 / src / code.h < prev    next >
C/C++ Source or Header  |  2000-01-04  |  2KB  |  94 lines

  1. #ifndef code_INCLUDED
  2. #define code_INCLUDED
  3.  
  4. #include "config.h"
  5. #include <ctype.h>
  6. #include <assert.h>
  7.  
  8. class Code
  9. {
  10.     //
  11.     // To facilitate the scanning, the character set is partitioned into
  12.     // 8 classes using the array CODE. The classes are described below
  13.     // together with some self-explanatory functions defined on CODE.
  14.     //
  15.     enum {
  16.              LOG_BASE_SIZE       = 9,
  17.              LOG_COMPLEMENT_SIZE = 7,
  18.              BASE_SIZE           = 512,
  19.              SLOT_SIZE           = 128,
  20.              SLOT_MASK           = 127,
  21.  
  22.              NEWLINE_CODE        = 1,
  23.              SPACE_CODE          = 2,
  24.              BAD_CODE            = 3,
  25.              DIGIT_CODE          = 4,
  26.              OTHER_DIGIT_CODE    = 5,
  27.              LOWER_CODE          = 6,
  28.              UPPER_CODE          = 7,
  29.              OTHER_LETTER_CODE   = 8
  30.          };
  31.  
  32.     static char code[39424];
  33.     static char *base[512];
  34.  
  35.  
  36. public:
  37.  
  38.     static inline void SetBadCode(wchar_t c)
  39.     {
  40.         base[c >> LOG_COMPLEMENT_SIZE][c] = BAD_CODE;
  41.     }
  42.  
  43.     static inline void CodeCheck(wchar_t c)
  44.     {
  45.          assert(c >> LOG_COMPLEMENT_SIZE < BASE_SIZE);
  46.          assert(base[c >> LOG_COMPLEMENT_SIZE] + c >= (&code[0]));
  47.          assert(base[c >> LOG_COMPLEMENT_SIZE] + c < (&code[39424]));
  48.     }
  49.  
  50.     static inline bool IsNewline(wchar_t c) // \r characters are replaced by \x0a in read_input.
  51.     {
  52.         return c == '\x0a';
  53.     }
  54.  
  55.     static inline bool IsSpaceButNotNewline(wchar_t c)
  56.     {
  57.         return base[c >> LOG_COMPLEMENT_SIZE][c] == SPACE_CODE;
  58.     }
  59.  
  60.     static inline bool IsSpace(wchar_t c)
  61.     {
  62.         return base[c >> LOG_COMPLEMENT_SIZE][c] <= SPACE_CODE;
  63.     }
  64.  
  65.     static inline bool IsDigit(wchar_t c)
  66.     {
  67.         return base[c >> LOG_COMPLEMENT_SIZE][c] == DIGIT_CODE;
  68.     }
  69.  
  70.     static inline bool IsUpper(wchar_t c)
  71.     {
  72.         return base[c >> LOG_COMPLEMENT_SIZE][c] == UPPER_CODE;
  73.     }
  74.  
  75.     static inline bool IsLower(wchar_t c)
  76.     {
  77.         return base[c >> LOG_COMPLEMENT_SIZE][c] == LOWER_CODE;
  78.     }
  79.  
  80.     static inline bool IsAlpha(wchar_t c)
  81.     {
  82.         return base[c >> LOG_COMPLEMENT_SIZE][c] >= LOWER_CODE;
  83.     }
  84.  
  85.     static inline bool IsAlnum(wchar_t c)
  86.     {
  87.         return base[c >> LOG_COMPLEMENT_SIZE][c] >= DIGIT_CODE;
  88.     }
  89.  
  90.  
  91. };
  92.  
  93. #endif
  94.